

function login() {
	var userName = dwr.util.getValue("userName");
	GameCenter.login(userName,showMainPage);
}

function showMainPage() {
	window.location = "http://localhost:8080/mainframe.html";
}

function initMainPage() {
	GameCenter.initShowMainPage();
}

function load(data) {
	
}

function showAllRooms(roomList){
	document.getElementById("joingame").innerHTML = '<input type="button" value="join" onclick="join()"/>';
	var rooms = new Array();
	for(var i=0;i<roomList.length; i++){
		var noOfUsers = 0;
		if(roomList[i].userList != null){
			noOfUsers = roomList[i].userList.length;
		}
		rooms[i] = {'roomName':roomList[i].roomName ,'noOfUsers':noOfUsers ,'state':roomList[i].roomState}
		//rooms[i] = {'roomName:'+roomList[i].roomName +'",'+'noOfUsers:"'+noOfUsers +'",'+'state:"'+roomList[i].roomState+'"'}
	}
	
	var myColumnDefs = [ 
	            {key:"roomName", label:"Room Name", sortable:true, resizeable:true}, 
	            {key:"noOfUsers",label:"No. of Users", sortable:true, resizeable:true}, 
	            {key:"state",lebel:"State", resizeable:true}
	        ]; 

	 myDataSource = new YAHOO.util.DataSource(rooms); 
	 myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY; 
		        myDataSource.responseSchema = { 
		            fields: ["roomName","noOfUsers","state"] 
		        }; 
		 
		        var myDataTable = new YAHOO.widget.DataTable("content", 
		                myColumnDefs, myDataSource, {caption:"DataTable Caption"}); 
		        
		        return { 
		            oDS: myDataSource, 
		            oDT: myDataTable 
		        }; 
	
}

function showAllUsers(userList) {
	var rooms = new Array();
	for(var i=0;i<userList.length; i++){
		var currRoom = "-";
		var roomOwner = "-";
		if(userList[i].currentRoom != null){
			currRoom = userList[i].currentRoom.roomName;
			roomOwner = userList[i].currentRoom.ownerId;
		}
		rooms[i] = {'userName':userList[i].userName ,'roomName':currRoom ,'state':roomOwner}
		//rooms[i] = {'roomName:'+roomList[i].roomName +'",'+'noOfUsers:"'+noOfUsers +'",'+'state:"'+roomList[i].roomState+'"'}
	}
	
	var myColumnDefs = [ 
	            {key:"userName", label:"User Name", sortable:true, resizeable:true}, 
	            {key:"roomName",label:"Room Name", sortable:true, resizeable:true}, 
	            {key:"owner",lebel:"Room Owner", resizeable:true}
	        ]; 

	 myDataSource = new YAHOO.util.DataSource(rooms); 
	 myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY; 
		        myDataSource.responseSchema = { 
		            fields: ["userName","roomName","owner"] 
		        }; 
		 
		        var myDataTable = new YAHOO.widget.DataTable("users", 
		                myColumnDefs, myDataSource, {caption:"DataTable Caption"}); 
		                 
		        return { 
		            oDS: myDataSource, 
		            oDT: myDataTable 
		        }; 
}

function addToMessage(data) {
	
}